package practice;

/**
 * 停车场问题
 */
public class ParkingLot {

    public static void main(String[] args) {
        int[] parks = {1, 1, 0, 0, 1, 1, 1, 1, 1};
        int result = 0;
        int continuousOne = 0;
        for (int park : parks) {
            if (park == 1) {
                continuousOne++;
            } else {
                result += parseNumber(continuousOne);
                continuousOne = 0;
            }
        }
        result+=parseNumber(continuousOne);
        System.out.println(result);
    }

    private static int parseNumber1(int num) {
        int count = 0;
        while (num > 0) {
            if (num >= 3) {
                count++;
                num-=3;
            } else if (num == 2) {
                count++;
                num-=2;
            } else {
                count++;
                num-=1;
            }
        }
        return count;
    }

    /**
     * 将一个整数分为1，2，3的和 使得分出来的元素个数最少
     * @param num
     * @return
     */
    private static int parseNumber(int num) {
        int threeCount = num/3;
        int twoCount = (num-threeCount * 3)/2;
        int oneCount = num - threeCount * 3 - twoCount *2;
        return oneCount+twoCount+threeCount;
    }
}
